package com.yq.cp.utils;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

@Configuration
public class UrlConvertUtil {
    @Value("${spring.profiles.active}")
    private String active="dev";
    public List<String> zh(String url){
        List<String> list=new ArrayList<>();
        if (url==null || url.equals("")){
            return list;
        }
        String[] split = url.split(",");
        for (int i = 0; i < split.length; i++) {
            String s = split[i];
            if (active.equals("dev")){
                //http://10.77.77.112/file/2024/11/01/a9f8d1f4-b619-4456-b4ac-e870e0376c77.jpg
                String qz="E:\\\\zh\\\\yunzaikafei\\\\file";
                s=s.replaceAll("http://10.77.77.112/file",qz);


                s=s.replaceAll("/","\\\\");
            }else {
                //http://gfnk.yuanqi86586.com/files/2024/11/01/a9f8d1f4-b619-4456-b4ac-e870e0376c77.jpg


                String qz="/mnt/files";
                s=s.replaceAll("http://gfnk.yuanqi86586.com/files",qz);
            }

            File file = new File(s);

            if (file.exists()) {
                list.add(s);
            } else {
                System.out.println("文件不存在");
            }
        }

        return list;
    }

    public static void main(String[] args) {
        UrlConvertUtil util=new UrlConvertUtil();
        List<String> zh = util.zh("http://gfnk.yuanqi86586.com/files/2024/11/01/a9f8d1f4-b619-4456-b4ac-e870e0376c77.jpg,http://gfnk.yuanqi86586.com/files/2024/11/01/a9f8d1f4-b619-4456-b4ac-e870e0376c77.jpg");
        System.out.println(zh);

    }
}
